package com.kamistoat.meimeichat.meimeichatserverapplication.netty.handlers;

import com.alibaba.fastjson.JSON;
import com.kamistoat.meimeichat.meimeichatserverapplication.netty.NettyServerBizHandler;
import com.kamistoat.meimeichat.meimeichatserverapplication.netty.service.NettyUserService;
import com.kamistoat.meimeichatserveraggrement.protocol.talk.DelTalkRequest;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 收起对话框请求 Handler.
 * 一个用户收起与另一个用户的聊天框时，仅仅是将该对话框收起，不会删除聊天记录
 */
@Component
@ChannelHandler.Sharable
public class DelTalkHandlerServer extends NettyServerBizHandler<DelTalkRequest> {
    @Autowired
    NettyUserService nettyUserService;

    /**
     * @Warning:子类只需要重写该方法
     */
    @Override
    public void channelRead(Channel channel, DelTalkRequest delTalkRequest) {
        if(delTalkRequest == null){
            return;
        }
        logger.info("收起对话框请求处理: " + JSON.toJSONString(delTalkRequest));
        nettyUserService.deleteUserTalk(delTalkRequest.getUserId(), delTalkRequest.getTalkId());
    }
}
